home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 2
/
Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso
/
Aminet
/
dev
/
misc
/
egs.lha
/
EGS
/
EGS_Devels
/
Examples
/
Other
/
poly.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-02-17
|
6KB
|
195 lines
/* star.c
*
* FM - 12.08.92
*
* Renders a moving band that changes it's colour permanently
*
*
* (c) by VIONA-Development 1992/93
*/
#include <exec/types.h>
#include <proto/exec.h>
#include <egs/egsintui.h>
#include <egs/proto/egsintui.h>
#include <egs/egsgfx.h>
#include <egs/proto/egsgfx.h>
#include <egs/egs.h>
#include <egs/proto/egs.h>
long RangeRand(int i );
/* the pointers to our libraries */
struct Library *EGSIntuiBase;
struct Library *EGSGfxBase;
struct Library *EGSBase;
/* description of a line */
struct Line
{
int used;
long x1,y1;
long x2,y2;
};
/* Draw a polygon with four edges */
void drawRect( EI_WindowPtr window, ULONG color,
struct Line *line1,
struct Line *line2 )
{
EG_RastPortPtr rp = window->RPort;
long top = window->BorderTop;
long left = window->BorderLeft;
EG_SetAPen( rp, color );
EG_AreaMove( rp, left+line1->x1, top+line1->y1 );
EG_AreaDraw( rp, left+line2->x1, top+line2->y1 );
EG_AreaDraw( rp, left+line2->x2, top+line2->y2 );
EG_AreaDraw( rp, left+line1->x2, top+line1->y2 );
EG_AreaEnd( rp );
}
/* something's happening here */
#define MAX_HISTORY 20
#define SPEED 11
#define COLORSPEED 6
void doThings( EI_WindowPtr window )
{
struct EG_AreaInfo areaInfo;
EG_Polygon areaBuffer[20];
struct Line history[MAX_HISTORY];
long x1,y1, x2,y2;
long dx1,dy1, dx2,dy2;
long dtime;
ULONG color;
ULONG dcolor;
int historyPos;
int i;
/* allocate TmpRas */
window->RPort->AreaInfo = EG_InitArea( &areaInfo, &areaBuffer[0],20 );
window->RPort->TmpRas = E_AllocBitMap( window->Width,
window->Height,1,E_PIXELMAP,0,
window->WScreen->EScreen->Map);
/* clear history */
for( i=0; i<MAX_HISTORY; i++ ) history[i].used = 0;
/* Startwert bestimmen */
x1 = RangeRand( window->Width-1 );
y1 = RangeRand( window->Height-1 );
x2 = RangeRand( window->Width-1 );
y2 = RangeRand( window->Height-1 );
dtime = 1;
color = window->WinColors.Back;
if (color % 256 != 0)
{
color = E_GetRGB8( window->WScreen->EScreen,color);
}
/* anmimation loop */
historyPos = 1;
history[0].x1 = x1;
history[0].y1 = y1;
history[0].x2 = x2;
history[0].y2 = y2;
history[0].used = 1;
while( GetMsg( window->UserPort )==NULL )
{
/* remove old part */
if ( history[historyPos].used )
{
drawRect( window, window->WinColors.Back,
&history[historyPos],
&history[(historyPos+1) % MAX_HISTORY] );
}
/* move everything by one step */
dtime--;
if ( dtime==0 )
{
dx1 = RangeRand( 2*SPEED ) - SPEED;
dy1 = RangeRand( 2*SPEED ) - SPEED;
dx2 = RangeRand( 2*SPEED ) - SPEED;
dy2 = RangeRand( 2*SPEED ) - SPEED;
dcolor = (((RangeRand(2*COLORSPEED) + 256 - COLORSPEED) % 256) << 24) +
(((RangeRand(2*COLORSPEED) + 256 - COLORSPEED) % 256) << 16) +
(((RangeRand(2*COLORSPEED) + 256 - COLORSPEED) % 256) << 8);
dtime = RangeRand( 100 ) + 10;
}
x1 += dx1;
if ( x1<0 || x1>=window->Width ) { x1 -= dx1; dx1 = -dx1; }
y1 += dy1;
if ( y1<0 || y1>=window->Height ) { y1 -= dy1; dy1 = -dy1; }
x2 += dx2;
if ( x2<0 || x2>=window->Width ) { x2 -= dx2; dx2 = -dx2; }
y2 += dy2;
if ( y2<0 || y2>=window->Height ) { y2 -= dy2; dy2 = -dy2; }
color += dcolor;
/* store the new value */
history[historyPos].x1 = x1;
history[historyPos].y1 = y1;
history[historyPos].x2 = x2;
history[historyPos].y2 = y2;
history[historyPos].used = 1;
/* render the new part */
drawRect( window, color,
&history[(historyPos+MAX_HISTORY-1) % MAX_HISTORY],
&history[historyPos]);
/* move through the cyclic buffer */
historyPos = (historyPos + 1) % MAX_HISTORY;
}
}
/* main program */
void main( int argc, char *argv[] )
{
static struct EI_NewWindow newWindow =
{
50,30, 400,300,
0,0, 0,0,
NULL,
EI_WINDOWCLOSE | EI_WINDOWBACK | EI_WINDOWDRAG,
NULL,
"Testfenster",
EI_SMART_REFRESH,
EI_iCLOSEWINDOW,
NULL,
{0,0,0,0,0,0,0},
NULL,
NULL
};
EI_WindowPtr window;
/* open libraries */
EGSIntuiBase = OpenLibrary( (UBYTE *)"egsintui.library", 0 );
if ( EGSIntuiBase )
{
EGSGfxBase = OpenLibrary( (UBYTE *)"egsgfx.library", 0 );
if ( EGSGfxBase )
{
EGSBase = OpenLibrary( (UBYTE *)"egs.library", 0 );
if ( EGSBase )
{
window = EI_OpenWindow( &newWindow );
if ( window )
{
doThings( window );
EI_CloseWindow( window );
}
CloseLibrary( EGSBase );
}
CloseLibrary( EGSGfxBase );
}
CloseLibrary( EGSIntuiBase );
}
}